﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Stat_EmpStat : System.Web.UI.Page
{
    Usas.BLL.Cms.AspPager ap = new Usas.BLL.Cms.AspPager();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SelUser1.IsOutCms = true;
            BindInit();
        }
    }

    private void BindInit()
    {
        if (Request["empid"] != null || Request["ip"] != null || Request["years"] != null || Request["months"] != null || Request["days"] != null)
        {
            txtYears.Text = Request["years"] == null ? "" : Request["years"].ToString();
            txtMonths.Text = Request["months"] == null ? "" : Request["months"].ToString();
            txtDays.Text = Request["days"] == null ? "" : Request["days"].ToString();
        }
        else
        {
            txtYears.Text = DateTime.Now.Year.ToString();
            txtMonths.Text = DateTime.Now.Month.ToString();
            txtDays.Text = DateTime.Now.Day.ToString();
        }
        SelUser1.SelUserInti(Request["empid"] != "" ? Request["empid"] : "", Request["ename"] != "" ? Request["ename"] : "");
        ipAdd.Text = Request["ip"] != null ? Server.UrlDecode(Request["ip"].ToString()) : "";

        Bind(Request["page"] == null || Request["page"].ToString() == "" ? 1 : Convert.ToInt32(Request["page"]));
    }

    private void Bind(int page)
    {
        string years = txtYears.Text.Trim().Length > 0 ? " and years=" + txtYears.Text.Trim() : "";
        string months = txtMonths.Text.Trim().Length > 0 ? " and months=" + txtMonths.Text.Trim() : "";
        string days = txtDays.Text.Trim().Length > 0 ? " and days=" + txtDays.Text.Trim() : "";
        string emp = SelUser1.EmployeeId != "" ? " and empid=" + SelUser1.EmployeeId : "";
        string ip = ipAdd.Text.Trim() != "" ? " and ip='" + ipAdd.Text.Trim() + "'" : "";
        DataTable dt = null;
        string usasdb = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringUsas"].ToString();

        string where = " 1=1 " + years + months + days + emp + ip;
        int count = 10;
        string table = " tb_dayStat as table1 left join tb_browser on (table1.browserId=tb_browser.browserid) " +
             "left join tb_system on (table1.systemId=tb_system.systemid) inner join " +
             "Usasdb.dbo.Employees as table2 on " +
             "(table1.empid=table2.employeeid) ";
        string PK = "id";
        string cols = "[id],empname,ip,years,months,days,systemname,browsername,sumNum";

        dt = ap.ShowListDesc(table, where, PK, count, page, cols);
        int cot = 0;
        if (dt != null && dt.Rows.Count > 0)
        {
            RptChatList.DataSource = dt;
            RptChatList.DataBind();

            apg.CurrentPageIndex = page;
            apg.PageSize = count;
            cot = ap.ShowListCount(table, where, PK);
            apg.RecordCount = cot;
        }
        else
        {
            DivContent.InnerHtml = "无记录";
        }
        nct.Text = cot.ToString();
        act.Text = ap.ShowListCount(table, "1=1", PK).ToString();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string years = txtYears.Text.Trim().Length > 0 ? " &years=" + txtYears.Text.Trim() : "";
        string months = txtMonths.Text.Trim().Length > 0 ? " &months=" + txtMonths.Text.Trim() : "";
        string days = txtDays.Text.Trim().Length > 0 ? " &days=" + txtDays.Text.Trim() : "";
        string emp = SelUser1.EmployeeId != "" ? " &empid=" + SelUser1.EmployeeId : "";
        string empname = SelUser1.EmpName != "" && SelUser1.EmployeeId != "" ? " &ename=" + Server.UrlEncode(SelUser1.EmpName) : "";
        string ip = ipAdd.Text.Trim() != "" ? " &ip=" + Server.UrlEncode(ipAdd.Text.Trim()) : "";
        Response.Redirect("EmpStat.aspx?" + years + months + days + emp + empname + ip);
    }
}
